local skel = fk.CreateSkill {
  name = "efengqi__tieji",
}

Fk:loadTranslationTable{
  ["efengqi__tieji"] = "铁骑",
  [":efengqi__tieji"] = "当你使用伤害牌指定唯一目标后，你可以进行一次判定，其执行两项：1.弃置一张同花色牌；2.本阶段无法使用基本牌；"..
  "3.本回合非锁定技失效。然后你可以执行剩余项，摸两张牌再弃置一张牌。",

  ["#efengqi__tieji-invoke"] = "你可以对 %src 发动“铁骑”，令其执行两项",
  ["#efengqi__tieji-discard"] = "铁骑：弃置一张%arg牌，否则本回合无法使用基本牌且非锁定技失效！",
  ["efengqi__tieji1"] = "弃置一张同花色牌",
  ["efengqi__tieji2"] = "本阶段无法使用基本牌",
  ["efengqi__tieji3"] = "本回合非锁定技失效",
  ["@@efengqi__tieji_basic-phase"] = "禁使用基本",
  ["@@efengqi__tieji_skill-turn"] = "非锁技失效",
  ["#efengqi__tieji-draw"] = "铁骑：是否令你%arg，摸2张牌再弃1张牌？",

  ["$efengqi__tieji1"] = "目标敌阵，全军突击！",
  ["$efengqi__tieji2"] = "敌人阵型已乱，随我杀！",
}

skel:addEffect(fk.TargetSpecified, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and data.card.is_damage_card
    and data:isOnlyTarget(data.to) and not data.to.dead
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askToSkillInvoke(player, {skill_name = skel.name, prompt = "#efengqi__tieji-invoke:" ..data.to.id }) then
      event:setCostData(self, { tos = {data.to} })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".",
    }
    room:judge(judge)
    if not judge.card then return end
    local to = data.to
    local suit = judge.card:getSuitString()
    if to.dead then return end
    local all_choices = {"efengqi__tieji2", "efengqi__tieji3"}
    if #room:askToDiscard(to, {
      min_num = 1, max_num = 1, skill_name = skel.name, include_equip = true, cancelable = true,
      pattern = ".|.|"..judge.card:getSuitString(), prompt = "#efengqi__tieji-discard:::"..suit
    }) > 0 then
      if not to.dead then
        local choice = room:askToChoice(to, { choices = all_choices, skill_name = self.name})
        table.removeOne(all_choices, choice)
        if choice == "efengqi__tieji2" then
          room:setPlayerMark(to, "@@efengqi__tieji_basic-phase", 1)
        elseif choice == "efengqi__tieji3" then
          room:setPlayerMark(to, "@@efengqi__tieji_skill-turn", 1)
          room:addPlayerMark(to, MarkEnum.UncompulsoryInvalidity.."-turn", 1)
        end
      end
    else
      room:setPlayerMark(to, "@@efengqi__tieji_basic-phase", 1)
      room:setPlayerMark(to, "@@efengqi__tieji_skill-turn", 1)
      room:addPlayerMark(to, MarkEnum.UncompulsoryInvalidity.."-turn", 1)
    end
    if player.dead then return end
    if #all_choices == 1 then
      if room:askToSkillInvoke(player, { skill_name = self.name, prompt = "#efengqi__tieji-draw:::"..all_choices[1] }) then
        if all_choices[1] == "efengqi__tieji2" then
          room:setPlayerMark(player, "@@efengqi__tieji_basic-phase", 1)
        elseif all_choices[1] == "efengqi__tieji3" then
          room:setPlayerMark(player, "@@efengqi__tieji_skill-turn", 1)
          room:addPlayerMark(player, MarkEnum.UncompulsoryInvalidity.."-turn", 1)
        end
        player:drawCards(2, self.name)
        room:askToDiscard(player, {min_num = 1, max_num = 1, include_equip = true, skill_name = skel.name, cancelable = false})
      end
    elseif #room:askToDiscard(player, {
      min_num = 1, max_num = 1, skill_name = skel.name, include_equip = true, cancelable = true,
      pattern = ".|.|"..judge.card:getSuitString(), prompt = "#efengqi__tieji-draw:::efengqi__tieji1"
    }) > 0 then
      if player.dead then return end
      player:drawCards(2, self.name)
      room:askToDiscard(player, {min_num = 1, max_num = 1, include_equip = true, skill_name = skel.name, cancelable = false})
    end
  end,
})

skel:addEffect("prohibit", {
  prohibit_use = function(self, player, card)
    return player:getMark("@@efengqi__tieji_basic-phase") ~= 0 and card and card.type == Card.TypeBasic
  end,
})

skel:addAI({
  think_skill_invoke = function(self, ai, skill_name, prompt)
    if type(prompt) ~= "string" then return false end
    if prompt:startsWith("#efengqi__tieji-invoke") then
      local data = ai.room.logic:getCurrentEvent().data -- 没法获取AimData只能获取UseData
      return true --ai:isEnemy(data.to)
    end
    return false
  end,
})

return skel
